< previous page page_109 next page >

Page 109
One-line Declarations
Be careful with one-line declarations such as the following:
9f31265bb40b592b1929e18a47ab28e5.gif
Dim intTemp, intCount As Integer
In this code, the variable intTemp is not actually given a data type. You may think that because theres an As Integer at the end of the line that both variables are declared as an integer type. However, the first variable, intTemp, is actually an untyped variable. A default data type is given to any untyped variable: the Variant data type. Youll learn about variants later in this chapter. If you want to make both of the variables an integer data type, you would change the code to read as follows:
9f31265bb40b592b1929e18a47ab28e5.gif
Dim intTemp As Integer, intCount As Integer
To make your code more readable, you should strive to put each variable declaration on a separate line. This not only looks better but it allows you to put a comment next to each variable describing what that variable does. Heres an example:
9f31265bb40b592b1929e18a47ab28e5.gif
Dim intTemp As Integer
Dim intCount As Integer
Assigning Values to Variables
The equal sign (=) is used to assign a value to a variable you declare. You cannot declare a variable and assign a value to it all in one statement. You must put the assignment on a separate line. Heres some code showing the different data types and how to assign values to them:
9f31265bb40b592b1929e18a47ab28e5.gif
Dim boolOK As Boolean
Dim bytValue As Byte
Dim dtBegin As Date
Dim dtTime As Date
Dim intLoop As Integer
Dim lngID As Long
Dim sngQty As Single
Dim dblAmount As Double
Dim curPrice As Currency
Dim strName As String

boolOK = True
bytValue = 1

 
< previous page page_109 next page >

If you like this book, buy it!